package com.example.demo.web.controller;

import com.example.demo.domain.base.BaseResult;
import com.example.demo.domain.base.PageResult;
import com.example.demo.domain.param.ProductCategoryCreateParam;
import com.example.demo.domain.param.ProductCategoryUpdateParam;
import com.example.demo.domain.param.ProductManagementParam;
import com.example.demo.domain.param.ProductManagementQueryParam;
import com.example.demo.domain.param.ProductManagementUpdateParam;
import com.example.demo.domain.vo.CategorySelectVO;
import com.example.demo.domain.vo.CategoryVO;
import com.example.demo.domain.vo.ProductManagementDetailVO;
import com.example.demo.domain.vo.ProductManagementVO;
import com.example.demo.service.ProductCategoryService;
import com.example.demo.service.ProductManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 商城管理
 *
 * @author haochen78
 * @date 2025/10/7 21:06
 **/
@RestController
@RequestMapping("/product")
public class ProductController {


    @Autowired
    private ProductCategoryService productCategoryService;
    @Autowired
    private ProductManagementService productManagementService;

    @PostMapping("/category-list")
    public BaseResult<List<CategoryVO>> listCategories() {
        return BaseResult.success(productCategoryService.list());
    }

    @GetMapping("/category-type")
    public BaseResult<List<CategorySelectVO>> typeCategories() {
        return BaseResult.success(productCategoryService.type());
    }

    @PostMapping("/category-add")
    public BaseResult<Void> createCategory(@RequestBody ProductCategoryCreateParam param) {
        productCategoryService.create(param);
        return BaseResult.success();
    }


    @PutMapping("/category-update")
    public BaseResult<Void> updateCategory(@RequestBody ProductCategoryUpdateParam param) {
        productCategoryService.update(param);
        return BaseResult.success();
    }

    @DeleteMapping("/category-delete/{id}")
    public BaseResult<Void> deleteCategory(@PathVariable Long id) {
        productCategoryService.delete(id);
        return BaseResult.success();
    }

    @PostMapping("/management-list")
    public BaseResult<PageResult<ProductManagementVO>> listManagement(ProductManagementQueryParam param) {
        return BaseResult.success(productManagementService.list(param));
    }
    
    @GetMapping("/management-detail")
    private BaseResult<ProductManagementDetailVO> managementDetail(@RequestParam() Long id){
        return BaseResult.success(productManagementService.getDetail(id));
    }

    @PostMapping("/management-add")
    public BaseResult<Void> createManagement(@RequestBody ProductManagementParam param) {
        productManagementService.create(param);
        return BaseResult.success();
    }


    @PutMapping("/management-update")
    public BaseResult<Void> updateManagement(@RequestBody ProductManagementParam param) {
        productManagementService.update(param);
        return BaseResult.success();
    }

    @PatchMapping("/management-update-selective")
    public BaseResult<Void> updateSelectiveManagement(@RequestBody ProductManagementUpdateParam param) {
        productManagementService.updateSelective(param);
        return BaseResult.success();
    }

    @DeleteMapping("/management-delete/{id}")
    public BaseResult<Void> deleteManagement(@PathVariable Long id) {
        productManagementService.delete(id);
        return BaseResult.success();
    }

}
